package xyf.p01.array_nodelist;

import commons.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * ClassName: P0083_RemoveDuplicates
 * Description:
 * Author: xyf
 * Date: 9/2/22 11:24 PM
 * Version: 1.0
 **/
public class P0083_RemoveDuplicates
{
    public ListNode deleteDuplicates(ListNode head)
    {
        if (null == head)
        {
            return null;
        }

        ListNode h = head;
        Set<Integer> valSet = new HashSet<>();
        valSet.add(head.val);
        while (null != head.next)
        {
            if (valSet.contains(head.next.val))
            {
                head.next = head.next.next;
            }
            else
            {
                valSet.add(head.next.val);
                head = head.next;
            }

        }
        return h;
    }
}
